package com.android.qjpmc.kernel;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by tree on 2016/8/25.
 */
public class JxtXmlPara
{
    public PwrDiagramObject m_Qjpmc_XmlCnfg = null;
    public String m_ChartPath = null;

    public int ReadJxtXml()
    {
        if( null == m_ChartPath)
        {
            return -1;
        }

        m_Qjpmc_XmlCnfg = new PwrDiagramObject();
        //构建XmlPullParserFactory
        try
        {
            XmlPullParserFactory pullParserFactory=XmlPullParserFactory.newInstance();
            //获取XmlPullParser的实例
            XmlPullParser xmlPullParser=pullParserFactory.newPullParser();
            //设置输入流  xml文件

            File xmlFile = new File(m_ChartPath);

            FileInputStream inputStream;
            try
            {
                 inputStream = new FileInputStream(xmlFile);
                 xmlPullParser.setInput(inputStream, "UTF-8");// 设置数据源编码
            }
            catch (Exception e)
            {
               // TODO Auto-generated catch block
                e.printStackTrace();
                return -1;
           }

            //开始
            int eventType=xmlPullParser.getEventType();
            PwrDiagramObject.Page JxtPage = null;

            try
            {
                while(eventType!=XmlPullParser.END_DOCUMENT)
                {

                    String nodeName=xmlPullParser.getName();
                    switch (eventType)
                    {
                        //文档开始
                        case XmlPullParser.START_DOCUMENT:
                            break;
                        //开始节点
                        case XmlPullParser.START_TAG:
                            //判断如果其实节点为PagePara
                            if("Screen".equals(nodeName))
                            {
                                m_Qjpmc_XmlCnfg.m_PageNum = Integer.parseInt(xmlPullParser.getAttributeValue(0));
                                m_Qjpmc_XmlCnfg.m_ScreenHeight = Integer.parseInt(xmlPullParser.getAttributeValue(1));
                                m_Qjpmc_XmlCnfg.m_ScreenWidth = Integer.parseInt(xmlPullParser.getAttributeValue(2));
                                m_Qjpmc_XmlCnfg.m_Page = new ArrayList<PwrDiagramObject.Page>();
                            }
                            else if("PagePara".equals(nodeName))
                            {
                                if(JxtPage == null)
                                {
                                    JxtPage = new PwrDiagramObject.Page();
                                }
                                JxtPage.m_PageID = Integer.parseInt(xmlPullParser.getAttributeValue(0) );
                                JxtPage.m_PageType = Integer.parseInt(xmlPullParser.getAttributeValue(1));
                                JxtPage.m_PageName = xmlPullParser.getAttributeValue(2);
                                JxtPage.m_BackColor = xmlPullParser.getAttributeValue(3);
                                JxtPage.m_ElementNum = Integer.parseInt(xmlPullParser.getAttributeValue(4));
                                JxtPage.m_StateComptNum = Integer.parseInt(xmlPullParser.getAttributeValue(5));
                                JxtPage.m_ValueComptNum = Integer.parseInt(xmlPullParser.getAttributeValue(6));
                                JxtPage.m_NormalBtnNum = Integer.parseInt(xmlPullParser.getAttributeValue(7));
                                JxtPage.m_InvisibleBtnNum = Integer.parseInt(xmlPullParser.getAttributeValue(8));

                                ReadGraph(xmlPullParser, JxtPage);
                            }
                            else if("ElementPara".equals(nodeName))
                            {
                                if(JxtPage.m_ElementNum ==  0)
                                {
                                    break;
                                }
                                JxtPage.m_Element = new ArrayList<PwrDiagramObject.Element>();
                                ReadElement(xmlPullParser, JxtPage.m_Element);
                            }
                            else if("StateComptPara".equals(nodeName))
                            {
                                if( JxtPage.m_StateComptNum ==  0)
                                {
                                    break;
                                }
                                JxtPage.m_StateComptList = new ArrayList<StateCompt>();
                                ReadStateCompt(xmlPullParser, JxtPage.m_StateComptList);
                            }
                            else if("ValueComptPara".equals(nodeName))//读取元件
                            {
                                if(JxtPage.m_ValueComptNum == 0)
                                {
                                    break;
                                }
                                JxtPage.m_ValueCompt = new ArrayList<PwrDiagramObject.ValueCompt>();
                            }
                            else if("ValueCompt".equals(nodeName))
                            {
                                PwrDiagramObject.ValueCompt ValueComptTemp = new PwrDiagramObject.ValueCompt();
                                ValueComptTemp.m_StartPoint = xmlPullParser.getAttributeValue(0);
                                ValueComptTemp.m_EndPoint = xmlPullParser.getAttributeValue(1);
                                ValueComptTemp.m_Unit = xmlPullParser.getAttributeValue(2);
                                ValueComptTemp.m_DecimalPlace = Integer.parseInt(xmlPullParser.getAttributeValue(3));
                                ValueComptTemp.m_FontSize = Integer.parseInt(xmlPullParser.getAttributeValue(4));
                                ValueComptTemp.m_TextColor = xmlPullParser.getAttributeValue(5);
                                ValueComptTemp.m_BackColor = xmlPullParser.getAttributeValue(6);
                                ValueComptTemp.m_StationID = Integer.parseInt(xmlPullParser.getAttributeValue(7));
                                ValueComptTemp.m_GroupIdx = Integer.parseInt(xmlPullParser.getAttributeValue(8));
                                ValueComptTemp.m_DataIdx = Integer.parseInt(xmlPullParser.getAttributeValue(9));
                                ValueComptTemp.m_AlignType = Integer.parseInt(xmlPullParser.getAttributeValue(10));
                                ValueComptTemp.m_DefaultValue = Float.parseFloat(xmlPullParser.getAttributeValue(11));

                                if(JxtPage.m_ValueCompt != null)
                                {
                                    JxtPage.m_ValueCompt.add(ValueComptTemp);
                                }
                            }
                            else if("ButtonPara".equals(nodeName))
                            {
                                if(JxtPage.m_NormalBtnNum == 0)
                                {
                                    break;
                                }
                                JxtPage.m_NormalBtn = new ArrayList<PwrDiagramObject.NormalBtn>();
                            }
                            else if("Button".equals(nodeName))
                            {
                                PwrDiagramObject.NormalBtn NormalBtnTemp = new PwrDiagramObject.NormalBtn();
                                NormalBtnTemp.m_StartPoint = xmlPullParser.getAttributeValue(0);
                                NormalBtnTemp.m_EndPoint = xmlPullParser.getAttributeValue(1);
                                NormalBtnTemp.m_BtnConText = xmlPullParser.getAttributeValue(2);
                                NormalBtnTemp.m_FuncType = Integer.parseInt(xmlPullParser.getAttributeValue(3));
                                NormalBtnTemp.m_FontSize = Integer.parseInt(xmlPullParser.getAttributeValue(4));
                                NormalBtnTemp.m_TextColor = xmlPullParser.getAttributeValue(5);
                                NormalBtnTemp.m_BackColor = xmlPullParser.getAttributeValue(6);
                                NormalBtnTemp.m_StationID = Integer.parseInt(xmlPullParser.getAttributeValue(7));
                                NormalBtnTemp.m_GroupIdx = Integer.parseInt(xmlPullParser.getAttributeValue(8));
                                NormalBtnTemp.m_DataIdx = Integer.parseInt(xmlPullParser.getAttributeValue(9));

                                if(JxtPage.m_NormalBtn != null)
                                {
                                    JxtPage.m_NormalBtn.add(NormalBtnTemp);
                                }
                            }
                            else if("InvisibleBtnPara".equals(nodeName))
                            {
                                if(JxtPage.m_InvisibleBtnNum == 0)
                                {
                                    break;
                                }
                                JxtPage.m_InvisibleBtn = new ArrayList<PwrDiagramObject.InvisibleBtn>();
                            }
                            else if("InvisibleBtn".equals(nodeName))
                            {
                                PwrDiagramObject.InvisibleBtn InvisibleBtnTemp = new PwrDiagramObject.InvisibleBtn();
                                InvisibleBtnTemp.m_StartPoint = xmlPullParser.getAttributeValue(0);
                                InvisibleBtnTemp.m_EndPoint = xmlPullParser.getAttributeValue(1);
                                InvisibleBtnTemp.m_FuncType = Integer.parseInt(xmlPullParser.getAttributeValue(2));
                                InvisibleBtnTemp.m_StationID = Integer.parseInt(xmlPullParser.getAttributeValue(3));
                                InvisibleBtnTemp.m_GroupIdx = Integer.parseInt(xmlPullParser.getAttributeValue(4));
                                InvisibleBtnTemp.m_DataIdx = Integer.parseInt(xmlPullParser.getAttributeValue(5));

                                if(JxtPage.m_InvisibleBtn != null)
                                {
                                    JxtPage.m_InvisibleBtn.add(InvisibleBtnTemp);
                                }
                            }
                            break;
                        //结束节点
                        case XmlPullParser.END_TAG:
                            if("PagePara".equals(nodeName))
                            {
                                m_Qjpmc_XmlCnfg.m_Page.add(JxtPage);
                                JxtPage = null;
                            }
                            break;
                        default:
                            break;
                    }
                    eventType=xmlPullParser.next();
                }
            } catch (NumberFormatException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
                return -1;
            }
        } catch (XmlPullParserException e) {
            e.printStackTrace();
            return -1;
        }
        return 0;
    }

    public int ReadGraph(XmlPullParser Parser, PwrDiagramObject.Page CurPage) {
        int eventType;
        try
        {
            if(Parser==null) return -1;
            if(CurPage==null) return -1;
            eventType = Parser.next();
            while(eventType!=XmlPullParser.END_DOCUMENT)
            {
                String nodeName=Parser.getName();
                switch (eventType)
                {
                    //开始节点
                    case XmlPullParser.START_TAG:
                        //判断如果其实节点为PagePara
                        if("GraphPara".equals(nodeName))
                        {
                            CurPage.m_TextNum = Integer.parseInt(Parser.getAttributeValue(0));
                            CurPage.m_ArcNum = Integer.parseInt(Parser.getAttributeValue(1));
                            CurPage.m_RectNum = Integer.parseInt(Parser.getAttributeValue(2));
                            CurPage.m_CircleNum = Integer.parseInt(Parser.getAttributeValue(3));
                            CurPage.m_LineNum = Integer.parseInt(Parser.getAttributeValue(4));
                            CurPage.m_PictureNum = Integer.parseInt(Parser.getAttributeValue(5));
                        }
                        else if("TextPara".equals(nodeName)) {
                            if(CurPage.m_TextNum==0) break;
                            CurPage.m_Text = new ArrayList<PwrDiagramObject.Text>();
                        }
                        else if("Text".equals(nodeName)) {
                            PwrDiagramObject.Text TextTemp = new PwrDiagramObject.Text();
                            TextTemp.m_StartPoint = Parser.getAttributeValue(0);
                            TextTemp.m_EndPoint = Parser.getAttributeValue(1);
                            TextTemp.m_Length = Integer.parseInt(Parser.getAttributeValue(2));
                            TextTemp.m_Context = Parser.getAttributeValue(3);
                            TextTemp.m_FontSize = Integer.parseInt(Parser.getAttributeValue(4));
                            TextTemp.m_TextColor = Parser.getAttributeValue(5);
                            TextTemp.m_BackColor = Parser.getAttributeValue(6);
                            TextTemp.m_AlignType = Integer.parseInt(Parser.getAttributeValue(7));
                            if(CurPage.m_Text!=null) CurPage.m_Text.add(TextTemp);
                        }
                        else if("LinePara".equals(nodeName)) {
                            if(CurPage.m_LineNum==0) break;
                            CurPage.m_Line = new ArrayList<PwrDiagramObject.Line>();
                        }
                        else if("Line".equals(nodeName)) {
                            PwrDiagramObject.Line LineTemp = new PwrDiagramObject.Line();
                            LineTemp.m_StartPoint = Parser.getAttributeValue(0);
                            LineTemp.m_EndPoint = Parser.getAttributeValue(1);
                            LineTemp.m_LineWidth = Integer.parseInt(Parser.getAttributeValue(2));
                            LineTemp.m_LineColor = Parser.getAttributeValue(3);
                            if(CurPage.m_Line!=null) CurPage.m_Line.add(LineTemp);
                        }
                        else if("CirclePara".equals(nodeName)) {
                            if(CurPage.m_CircleNum==0) break;
                            CurPage.m_Circle = new ArrayList<PwrDiagramObject.Circle>();
                        }
                        else if("Circle".equals(nodeName)) {
                            PwrDiagramObject.Circle CircleTemp = new PwrDiagramObject.Circle();
                            CircleTemp.m_StartPoint = Parser.getAttributeValue(0);
                            CircleTemp.m_EndPoint = Parser.getAttributeValue(1);
                            CircleTemp.m_LineWidth = Integer.parseInt(Parser.getAttributeValue(2));
                            CircleTemp.m_FillSign = (byte)Integer.parseInt(Parser.getAttributeValue(3));
                            CircleTemp.m_LineColor = Parser.getAttributeValue(4);
                            CircleTemp.m_FillColor = Parser.getAttributeValue(5);
                            if(CurPage.m_Circle!=null) CurPage.m_Circle.add(CircleTemp);
                        }
                        else if("RectPara".equals(nodeName)) {
                            if(CurPage.m_RectNum==0) break;
                            CurPage.m_Rect = new ArrayList<PwrDiagramObject.Rect>();
                        }
                        else if("Rect".equals(nodeName)) {
                            PwrDiagramObject.Rect RectTemp = new PwrDiagramObject.Rect();
                            RectTemp.m_StartPoint = Parser.getAttributeValue(0);
                            RectTemp.m_EndPoint = Parser.getAttributeValue(1);
                            RectTemp.m_LineWidth = Integer.parseInt(Parser.getAttributeValue(2));
                            RectTemp.m_FillSign = (byte)Integer.parseInt(Parser.getAttributeValue(3));
                            RectTemp.m_LineColor = Parser.getAttributeValue(4);
                            RectTemp.m_FillColor = Parser.getAttributeValue(5);
                            if(CurPage.m_Rect!=null) CurPage.m_Rect.add(RectTemp);
                        }
                        else if("ArcPara".equals(nodeName)) {
                            if(CurPage.m_ArcNum==0) break;
                            CurPage.m_Arc = new ArrayList<PwrDiagramObject.Arc>();
                        }
                        else if("Arc".equals(nodeName)) {
                            PwrDiagramObject.Arc ArcTemp = new PwrDiagramObject.Arc();
                            ArcTemp.m_StartPoint = Parser.getAttributeValue(0);
                            ArcTemp.m_EndPoint = Parser.getAttributeValue(1);
                            ArcTemp.m_LineWidth = Integer.parseInt(Parser.getAttributeValue(2));
                            ArcTemp.m_LineColor = Parser.getAttributeValue(3);
                            ArcTemp.m_StartAngle = Integer.parseInt(Parser.getAttributeValue(4));
                            ArcTemp.m_EndAngle = Integer.parseInt(Parser.getAttributeValue(5));
                            if(CurPage.m_Arc!=null) CurPage.m_Arc.add(ArcTemp);
                        }
                        else if("PicturePara".equals(nodeName)) {
                            if(CurPage.m_PictureNum==0) break;
                            CurPage.m_Picture = new ArrayList<PwrDiagramObject.Picture>();
                        }
                        else if("Picture".equals(nodeName)) {
                            PwrDiagramObject.Picture PictureTemp = new PwrDiagramObject.Picture();
                            PictureTemp.m_StartPoint = Parser.getAttributeValue(0);
                            PictureTemp.m_EndPoint = Parser.getAttributeValue(1);
                            PictureTemp.m_PicLink = Parser.getAttributeValue(2);
                            PictureTemp.m_BackColor = Parser.getAttributeValue(3);
                            PictureTemp.m_TransparentSign = (byte)Integer.parseInt(Parser.getAttributeValue(4));
                            if(CurPage.m_Picture!=null) CurPage.m_Picture.add(PictureTemp);
                        }
                        break;
                    //结束节点
                    case XmlPullParser.END_TAG:
                        if("GraphPara".equals(nodeName))
                        {
                            return 0;
                        }
                        else if("GraphPara".equals(nodeName)) {
                        }
                        break;
                    default:
                        break;
                }
                eventType=Parser.next();
            }
        }
        catch (NumberFormatException e) {
            e.printStackTrace();
        }
        catch (IOException e) {
            e.printStackTrace();
        }
        catch (XmlPullParserException e) {
        e.printStackTrace();
        }

        return 1;
    }

    public int ReadElement(XmlPullParser Parser,List<PwrDiagramObject.Element> ElementList) {
        int eventType;
        PwrDiagramObject.Element ElementTemp=new PwrDiagramObject.Element();
        try {
            if(Parser==null) return -1;
            if(ElementList==null) return -1;
            eventType = Parser.next();
            while(eventType!=XmlPullParser.END_DOCUMENT){
                String nodeName=Parser.getName();
                switch (eventType) {
                    //开始节点
                    case XmlPullParser.START_TAG:
                        //判断如果其实节点为PagePara
                        if("Element".equals(nodeName)){
                            if(ElementTemp==null) ElementTemp=new PwrDiagramObject.Element();
                            ElementTemp.m_StartPoint = Parser.getAttributeValue(0);
                            ElementTemp.m_EndPoint = Parser.getAttributeValue(1);
                            ElementTemp.m_ElementName = Parser.getAttributeValue(2);
                            ElementTemp.m_TextNum = Integer.parseInt(Parser.getAttributeValue(3));
                            ElementTemp.m_ArcNum = Integer.parseInt(Parser.getAttributeValue(4));
                            ElementTemp.m_RectNum = Integer.parseInt(Parser.getAttributeValue(5));
                            ElementTemp.m_CircleNum = Integer.parseInt(Parser.getAttributeValue(6));
                            ElementTemp.m_LineNum = Integer.parseInt(Parser.getAttributeValue(7));
                            ElementTemp.m_PictureNum = Integer.parseInt(Parser.getAttributeValue(8));
                        }
                        else if("TextPara".equals(nodeName)) {
                            if(ElementTemp==null) break;
                            if(ElementTemp.m_TextNum==0) break;
                            ElementTemp.m_Text = new ArrayList<PwrDiagramObject.Text>();
                        }
                        else if("Text".equals(nodeName)) {
                            if(ElementTemp==null) break;
                            PwrDiagramObject.Text TextTemp = new PwrDiagramObject.Text();
                            TextTemp.m_StartPoint = Parser.getAttributeValue(0);
                            TextTemp.m_EndPoint = Parser.getAttributeValue(1);
                            TextTemp.m_Length = Integer.parseInt(Parser.getAttributeValue(2));
                            TextTemp.m_Context = Parser.getAttributeValue(3);
                            TextTemp.m_FontSize = Integer.parseInt(Parser.getAttributeValue(4));
                            TextTemp.m_TextColor = Parser.getAttributeValue(5);
                            TextTemp.m_BackColor = Parser.getAttributeValue(6);
                            TextTemp.m_AlignType = Integer.parseInt(Parser.getAttributeValue(7));
                            if(ElementTemp.m_Text!=null) ElementTemp.m_Text.add(TextTemp);
                        }
                        else if("LinePara".equals(nodeName)) {
                            if(ElementTemp==null) break;
                            if(ElementTemp.m_LineNum==0) break;
                            ElementTemp.m_Line = new ArrayList<PwrDiagramObject.Line>();
                        }
                        else if("Line".equals(nodeName)) {
                            if(ElementTemp==null) break;
                            PwrDiagramObject.Line LineTemp = new PwrDiagramObject.Line();
                            LineTemp.m_StartPoint = Parser.getAttributeValue(0);
                            LineTemp.m_EndPoint = Parser.getAttributeValue(1);
                            LineTemp.m_LineWidth = Integer.parseInt(Parser.getAttributeValue(2));
                            LineTemp.m_LineColor = Parser.getAttributeValue(3);
                            if(ElementTemp.m_Line!=null) ElementTemp.m_Line.add(LineTemp);
                        }
                        else if("CirclePara".equals(nodeName)) {
                            if(ElementTemp==null) break;
                            if(ElementTemp.m_CircleNum==0) break;
                            ElementTemp.m_Circle = new ArrayList<PwrDiagramObject.Circle>();
                        }
                        else if("Circle".equals(nodeName)) {
                            PwrDiagramObject.Circle CircleTemp = new PwrDiagramObject.Circle();
                            CircleTemp.m_StartPoint = Parser.getAttributeValue(0);
                            CircleTemp.m_EndPoint = Parser.getAttributeValue(1);
                            CircleTemp.m_LineWidth = Integer.parseInt(Parser.getAttributeValue(2));
                            CircleTemp.m_FillSign = (byte)Integer.parseInt(Parser.getAttributeValue(3));
                            CircleTemp.m_LineColor = Parser.getAttributeValue(4);
                            CircleTemp.m_FillColor = Parser.getAttributeValue(5);
                            if(ElementTemp.m_Circle!=null) ElementTemp.m_Circle.add(CircleTemp);
                        }
                        else if("RectPara".equals(nodeName)) {
                            if(ElementTemp==null) break;
                            if(ElementTemp.m_RectNum==0) break;
                            ElementTemp.m_Rect = new ArrayList<PwrDiagramObject.Rect>();
                        }
                        else if("Rect".equals(nodeName)) {
                            if(ElementTemp==null) break;
                            PwrDiagramObject.Rect RectTemp = new PwrDiagramObject.Rect();
                            RectTemp.m_StartPoint = Parser.getAttributeValue(0);
                            RectTemp.m_EndPoint = Parser.getAttributeValue(1);
                            RectTemp.m_LineWidth = Integer.parseInt(Parser.getAttributeValue(2));
                            RectTemp.m_FillSign = (byte)Integer.parseInt(Parser.getAttributeValue(3));
                            RectTemp.m_LineColor = Parser.getAttributeValue(4);
                            RectTemp.m_FillColor = Parser.getAttributeValue(5);
                            if(ElementTemp.m_Rect!=null) ElementTemp.m_Rect.add(RectTemp);
                        }
                        else if("ArcPara".equals(nodeName)) {
                            if(ElementTemp==null) break;
                            if(ElementTemp.m_ArcNum==0) break;
                            ElementTemp.m_Arc = new ArrayList<PwrDiagramObject.Arc>();
                        }
                        else if("Arc".equals(nodeName)) {
                            if(ElementTemp==null) break;
                            PwrDiagramObject.Arc ArcTemp = new PwrDiagramObject.Arc();
                            ArcTemp.m_StartPoint = Parser.getAttributeValue(0);
                            ArcTemp.m_EndPoint = Parser.getAttributeValue(1);
                            ArcTemp.m_LineWidth = Integer.parseInt(Parser.getAttributeValue(2));
                            ArcTemp.m_LineColor = Parser.getAttributeValue(3);
                            ArcTemp.m_StartAngle = Integer.parseInt(Parser.getAttributeValue(4));
                            ArcTemp.m_EndAngle = Integer.parseInt(Parser.getAttributeValue(5));
                            if(ElementTemp.m_Arc!=null) ElementTemp.m_Arc.add(ArcTemp);
                        }
                        else if("PicturePara".equals(nodeName)) {
                            if(ElementTemp==null) break;
                            if(ElementTemp.m_PictureNum==0) break;
                            ElementTemp.m_Picture = new ArrayList<PwrDiagramObject.Picture>();
                        }
                        else if("Picture".equals(nodeName)) {
                            if(ElementTemp==null) break;
                            PwrDiagramObject.Picture PictureTemp = new PwrDiagramObject.Picture();
                            PictureTemp.m_StartPoint = Parser.getAttributeValue(0);
                            PictureTemp.m_EndPoint = Parser.getAttributeValue(1);
                            PictureTemp.m_PicLink = Parser.getAttributeValue(2);
                            PictureTemp.m_BackColor = Parser.getAttributeValue(3);
                            PictureTemp.m_TransparentSign = (byte)Integer.parseInt(Parser.getAttributeValue(4));
                            if(ElementTemp.m_Picture!=null) ElementTemp.m_Picture.add(PictureTemp);
                        }
                        break;
                    //结束节点
                    case XmlPullParser.END_TAG:
                        if("Element".equals(nodeName))
                        {
                            if(ElementTemp != null)
                            {
                                ElementList.add(ElementTemp);
                            }
                            ElementTemp = null;
                        }
                        else if("ElementPara".equals(nodeName)) {
                            return 0;
                        }
                        else if("StateCompt".equals(nodeName)) {
                            return 0;
                        }
                        break;
                    default:
                        break;
                }
                eventType=Parser.next();
            }
        }
        catch (NumberFormatException e) {
            e.printStackTrace();
        }
        catch (IOException e) {
            e.printStackTrace();
        }
        catch (XmlPullParserException e) {
            e.printStackTrace();
        }

        return 1;
    }

    public int ReadStateCompt(XmlPullParser Parser,List<StateCompt> StateComptList) {
        int eventType;
        StateCompt StateComptTemp=new StateCompt();
        try {
            if(Parser==null) return -1;
            if(StateComptList==null) return -1;
            eventType = Parser.next();
            while(eventType!=XmlPullParser.END_DOCUMENT){
                String nodeName=Parser.getName();
                switch (eventType) {
                    //开始节点
                    case XmlPullParser.START_TAG:
                        //判断如果其实节点为PagePara
                        if("StateCompt".equals(nodeName)){
                            if(StateComptTemp==null) StateComptTemp=new StateCompt();
                            StateComptTemp.m_StationID = Integer.parseInt(Parser.getAttributeValue(0));
                            StateComptTemp.m_GroupIdx = Integer.parseInt(Parser.getAttributeValue(1));
                            StateComptTemp.m_DataIdx = Integer.parseInt(Parser.getAttributeValue(2));
                            StateComptTemp.m_StateNum = Integer.parseInt(Parser.getAttributeValue(3));
                            StateComptTemp.m_ShowType = Integer.parseInt(Parser.getAttributeValue(4));
                            StateComptTemp.m_DefaultState = (byte)Integer.parseInt(Parser.getAttributeValue(5));
                            StateComptTemp.m_ShowPos=1;

                            if(StateComptTemp.m_StateNum>0) StateComptTemp.m_Element=new ArrayList<PwrDiagramObject.Element>();
                            ReadElement(Parser, StateComptTemp.m_Element);

                            StateComptList.add(StateComptTemp);
                            StateComptTemp=null;
                        }
                    //结束节点
                    case XmlPullParser.END_TAG:
                        if("StateComptPara".equals(nodeName)){
                            return 0;
                        }
                        break;
                    default:
                        break;
                }
                eventType=Parser.next();
            }
        }
        catch (NumberFormatException e) {
            e.printStackTrace();
        }
        catch (IOException e) {
            e.printStackTrace();
        }
        catch (XmlPullParserException e) {
            e.printStackTrace();
        }

        return 1;
    }

}
